package com.wps.wdztv6.service.impl;

import com.wps.wdztv6.entity.User;
import com.wps.wdztv6.mapper.UserInfoMapper;
import com.wps.wdztv6.service.UserInfoService;
import com.wps.wdztv6.utils.AvatarUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.OutputStream;

@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Value("${myserver.api}")
    private String serverApi;
    @Autowired
    UserInfoMapper userInfoMapper;

    @Override
    public String genUserAvatarLink(String userId) {
        return String.format("%s/user/%s",serverApi,userId);
    }

    @Override
    public void outputUserAvatar(String userId, OutputStream outputStream) throws IOException {
        User userInfo = userInfoMapper.selectById(userId);
        if (userInfo == null) {
            AvatarUtil.generateImg(userId,outputStream);
        }else{
            AvatarUtil.generateImg(userInfo.getName(),outputStream);
        }
    }
}
